
<?php
error_reporting('IGNORE_REPEATED_ERRORS');
$updated_notice_title = str_replace(array("\n", "\r", "\o", "\xOB"), '', trim(nl2br($_POST["updated_notice_title"])));
$updated_notice_body = str_replace(array("\n", "\r", "\o", "\xOB"), '', trim(nl2br($_POST["updated_notice_body"])));
$updated_publish_date = $_POST["updated_publish_date"];
$updated_purge_date = $_POST["updated_purge_date"];
$notice_title = $_POST["notice_title"];
$new_notice_title = "newtitle";
?>

<HTML>
<HEAD>
<script type="text/javascript" src="datepickercontrol/datepickercontrol.js"></script>
<script type="text/javascript">
function update(index){
	if (isNaN(index)) {
		document.getElementById("notices_manager").reset();
	}else{
		document.getElementById("notices_manager").updated_notice_title.value = title[index];
		document.getElementById("notices_manager").updated_notice_body.value = body[index];
		document.getElementById("notices_manager").updated_publish_date.value = publish[index];
		document.getElementById("notices_manager").updated_purge_date.value = purge[index];
	}
}
</script>
<link type="text/css" rel="stylesheet" href="datepickercontrol/datepickercontrol.css"> 
</HEAD>
<BODY>
<FORM action="./manage_notices.php" method=POST name=notices_manager id=notices_manager>
<B>This form allows you to change the notices in the system.</B><BR><BR>



<?php

//echo "<BR><BR>"; 
//echo "1) $notice_title <BR> 2) $updated_notice_title <BR> 3) $updated_notice_body <BR> 4) $updated_publish_date <BR> 5) $updated_purge_date";
//echo "<BR><BR>";

mysql_connect("localhost", "root", "") or
    die("Could not connect: " . mysql_error());
mysql_select_db("QA");

if( (strlen($notice_title)>0) && (strlen($updated_notice_title)>0) && (strlen($updated_notice_body)>0) ){
	if( strcmp($notice_title, $new_notice_title)==0 ){
		mysql_query("insert into QA.Notices (Title, Body, Publish_Date, Purge_Date) VALUES (\"$updated_notice_title\", \"$updated_notice_body\", \"$updated_publish_date\", \"$updated_purge_date\")");
		echo "<I>New Notice Created \"$updated_notice_title\".</I><BR><BR>";
	}else{
		mysql_query("update QA.Notices SET Title=\"".$updated_notice_title."\", Body=\"".$updated_notice_body."\" where Title=\"".$current_notice_title."\"");
		echo "<I>Updated ".$current_notice_title." to ".$updated_notice_title.".</I><BR><BR>";
	}
}




$result = mysql_query("select Distinct Title, Body, Publish_Date, Purge_Date from QA.Notices");
$titles = Array();
$body = Array();
$publish = Array();
$purge = Array();
$i = -1;
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	$i = $i + 1;
	$title[$i] = $row[0];
	$body[$i] = $row[1];
	$publish[$i] = $row[2];
	$purge[$i] = $row[3];
}

mysql_free_result($result);


echo "<SCRIPT type=\"text/javascript\">\r\n<!--\r\n";
echo "var title = new Array();\r\n";
echo "var body = new Array();\r\n";
echo "var publish = new Array();\r\n";
echo "var purge = new Array();\r\n";
$j = 0;
while ($j<=$i){
	echo "title[$j] = \"$title[$j]\";\r\n";
	echo "body[$j] = \"$body[$j]\";\r\n";
	echo "publish[$j] = \"$publish[$j]\";\r\n";
	echo "purge[$j] = \"$purge[$j]\";\r\n";
	$j = $j+1;
}
echo "-->\r\n</SCRIPT>\r\n<BR>";


echo "Current Notices (Select one to view/update, to create a new one select \"New Notice\")<BR>";
echo "<select name=current_notice_index id=current_notice_index onBlur=\"javascript:update(current_notice_index.value);\">\r\n";
echo "<option value=\"$new_notice_title\">New Notice</OPTION>\r\n";
$i = 0;
foreach($title as $current) {
	echo "<OPTION value=\"".$i."\">".$current."</OPTION>\r\n";
	$i = $i + 1;
}
echo "</SELECT>\r\n<BR>";
echo "<INPUT type=\"hidden\" name=notice_title id=notice_title value=\"$new_notice_title\"/>\r\n";
?>
<BR>
Title: 
<TEXTAREA size=255 rows=2 cols=100 name=updated_notice_title id=updated_notice_title></TEXTAREA><BR>
Body:
<TEXTAREA size=2048 rows=20 cols=100 name=updated_notice_body id=updated_notice_body></TEXTAREA><BR>
<input type="hidden" id="DPC_TODAY_TEXT" value="today">
<input type="hidden" id="DPC_BUTTON_TITLE" value="Open calendar...">
<input type="hidden" id="DPC_MONTH_NAMES" value="['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']">
<input type="hidden" id="DPC_DAY_NAMES" value="['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']">
<input type="hidden" id="DPC_DEFAULT_FORMAT" value="YYYY-MM-DD">
<input type="hidden" id="DPC_SUBMIT_FORMAT" value="YYYY-MM-DD">
Publish Date: <input type="text" name="updated_publish_date" id="updated_publish_date" size="12" style="border-width:1px;" datepicker="true"><BR>
Purge Date: <input type="text" name="updated_purge_date" id="updated_purge_date" size="12" style="border-width:1px;" datepicker="true"><BR>
<BR>
<INPUT type=SUBMIT name=SUBMIT /><INPUT type=RESET name=RESET />
</FORM>
<BODY>
</HTML>